<template>
  <div>
    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      class="j-table-force-nowrap"
      :scroll="{ x: true }"
      :columns="routingColumns"
      :dataSource="routingList"
    >
      <template slot="action" slot-scope="text, record">
        <a @click="routingDetail(record)">详情</a>
      </template>
    </a-table>
    <inspection-record-modal ref="routingForm" />
  </div>
</template>

<script>
import '@/assets/less/TableExpand.less'
import InspectionRecordModal from '@/views/qms/quality-inspection/modules/InspectionRecordModal'
import { getAction } from '@api/manage'

export default {
  name: 'routing',
  components: { InspectionRecordModal },
  data() {
    return {
      description: '巡检信息',
      routingList: [],
      routingColumns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '巡检单号',
          align: 'center',
          dataIndex: 'recordNumber',
        },
        {
          title: '巡检标准名称',
          align: 'center',
          dataIndex: 'standardName',
        },
        {
          title: '计划单号',
          align: 'center',
          dataIndex: 'planNumber',
        },
        {
          title: '巡检结果',
          align: 'center',
          dataIndex: 'result_dictText',
        },
        {
          title: '巡检人',
          align: 'center',
          dataIndex: 'createBy_dictText',
        },
        {
          title: '巡检部门',
          align: 'center',
          dataIndex: 'sysOrgCode_dictText',
        },
        {
          title: '巡检时间',
          align: 'center',
          dataIndex: 'createTime',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 70,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        routinglist: '/qms/inspection/inspection-record/allList',
      },
    }
  },
  methods: {
    loadRoutingData(batchNumber) {
      this.routingList = []
      if (batchNumber) {
        getAction(this.url.routinglist, { batchNumber: batchNumber }).then((res) => {
          if (res.success) {
            this.routingList = res.result.records || res.result || []
          }
        })
      }
    },
    routingDetail: function (record) {
      this.$refs.routingForm.edit(record)
      this.$refs.routingForm.title = '详情'
      this.$refs.routingForm.disableSubmit = true
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
::v-deep .ant-table-tbody tr {
  height: 36px !important;
}
</style>
